package com.zc.manager.network.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.manager.network.domain.IotCertificateInfo;
import com.zc.manager.network.service.IIotCertificateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 证书Controller类
 *
 * @author zhaoxainglong
 * @date 2022-11-7
 */
@RestController
@RequestMapping("/iot/certificate")
public class IotCertificateController extends BaseController {
    @Resource
    private IIotCertificateService iotCertificateService;

    /**
     * 查询
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo listCertificate(IotCertificateInfo iotCertificateInfo) {
        startPage();
        return getDataTable(iotCertificateService.listCertificate(iotCertificateInfo));
    }
    /**
     * 无分页查询
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:list')")
    @GetMapping("/query")
    public AjaxResult queryCertificate(IotCertificateInfo iotCertificateInfo) {
        return AjaxResult.success(iotCertificateService.listCertificate(iotCertificateInfo));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:add')")
    @Log(title = "证书新增", businessType = BusinessType.IMPORT)
    @PostMapping
    public AjaxResult addCertificate(@RequestBody IotCertificateInfo iotCertificateInfo) {
        return toAjax(iotCertificateService.addCertificate(iotCertificateInfo));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:edit')")
    @Log(title = "证书修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult editCertificate(@RequestBody IotCertificateInfo iotCertificateInfo) {
        return toAjax(iotCertificateService.editCertificate(iotCertificateInfo));
    }

    /**
     * 查询详情
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:query')")
    @GetMapping("/{id}")
    public AjaxResult getCertificate(@PathVariable Long id) {
        return AjaxResult.success(iotCertificateService.getCertificate(id));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:remove')")
    @Log(title = "证书删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult removeCertificate(@PathVariable List<Long> ids) {
        return toAjax(iotCertificateService.removeByIds(ids));
    }

    /**
     * 导出
     */
    @PreAuthorize("@ss.hasPermi('iot:certificate:export')")
    @Log(title = "导出文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotCertificateInfo iotCertificateInfo) {
        List<IotCertificateInfo> list = iotCertificateService.selectIotCertificateList(iotCertificateInfo);
        ExcelUtil<IotCertificateInfo> util = new ExcelUtil<>(IotCertificateInfo.class);
        util.exportExcel(response, list, "证书数据");
    }

}
